package com.jbm.jbmsupplier.activity.searchmanage.presenter;

import android.content.Context;

import com.jbm.jbmsupplier.activity.rxjavanet.ModeRxjavaNet;
import com.jbm.jbmsupplier.activity.searchmanage.view.SearchManageInt;
import com.jbm.jbmsupplier.adapter.Perm_Manage_Adapter;
import com.jbm.onehome.iface.LoginEntity;

import java.util.ArrayList;

import rx.Observable;
import rx.Observer;
import rx.Subscriber;

/**
 * Created by 家帮忙 on 2017/9/21.
 */

public class Search_Pre implements Search_Pre_Int {
    Context context;
    SearchManageInt search;
    private Perm_Manage_Adapter permadapter;
//    PreManageAdapter permadapter;
    public Search_Pre(Context context, SearchManageInt search) {
        this.context = context;
        this.search = search;

    }



    @Override
    public void getAllMan() {
        ModeRxjavaNet.Companion.getInstantMode().objects(Observable.create(new Observable.OnSubscribe<LoginEntity>() {
            @Override
            public void call(Subscriber<? super LoginEntity> subscriber) {
                subscriber.onNext(ModeRxjavaNet.Companion.getInstantMode().getOhInter().getAllUnitPerson());
        }
        })).subscribe(new Observer<LoginEntity>() {
            @Override
            public void onCompleted() {

            }
            @Override
            public void onError(Throwable e) {

            }
            @Override
            public void onNext(LoginEntity loginEntity) {
          if (loginEntity.m_code==200){
              ArrayList<LoginEntity> array=new ArrayList<LoginEntity>();
            if (loginEntity.getLoginList()!=null) {
                array.addAll(loginEntity.getLoginList());
            }
              for (int i = 0; i <array.size() ; i++) {
                  if (array.get(i).getPrivilegeList()!=null)
                  for (int j = 0; j <array.get(i).getPrivilegeList().size() ; j++) {
                      if (array.get(i).getPrivilegeList().get(j).getPriCode().equals("ProPManager")){
                          array.remove(array.get(i));
                          break;
                      }
                  }
              }

//              search.getpull().setLinearLayout();
//              search.getpull().setPullRefreshEnable(false);
////              不需要上拉刷新
//              search.getpull().setPushRefreshEnable(false);
              permadapter = new Perm_Manage_Adapter(context,array);
              search.getpull().setAdapter(permadapter);
          }else{


            }
            }
        });
    }
    
    

}
